<template>
  <div v-if="editor">
    <button @click="addImage">添加网络图片URL</button>
  </div>
  <editor-content :editor="editor" />
</template>

<script setup>
import Document from '@tiptap/extension-document'
import Dropcursor from '@tiptap/extension-dropcursor'
import Image from '@tiptap/extension-image'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import { useEditor, EditorContent } from '@tiptap/vue-3'



const editor = useEditor({
  content: `
  <p>This is a basic example of implementing images. Drag to re-order.</p>
        <img src="https://source.unsplash.com/8xznAGy4HcY/800x400" />
        <img src="https://source.unsplash.com/K9QHL52rE2k/800x400" />
  `,
  extensions: [
    Document,
        Paragraph,
        Text,
        Image,
        Dropcursor,
  ],
})

function addImage() {
      const url = window.prompt('URL')

      if (url) {
        editor.chain().focus().setImage({ src: url }).run()
      }
    }
</script>

<style lang="scss">
/* Basic editor styles */
.ProseMirror {
  > * + * {
    margin-top: 0.75em;
  }

  img {
    max-width: 100%;
    height: auto;

    &.ProseMirror-selectednode {
      outline: 3px solid #68CEF8;
    }
  }
}
</style>
